using System;
using System.Collections.Generic;
using System.Text;
using Coriander.Xmpp;

namespace Coriander.Xmpp.Jabber
{
    /// <summary>
    /// 
    /// </summary>
    public class JabberConnectionPolicy : IConnectionPolicy
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        /// <param name="version"></param>
        /// <param name="language"></param>
        /// <returns></returns>
        Message GetStreamStartHeaderCore(
            String host,
            Object version,
            String language
        )
        {
            if (null == host)
                throw new ArgumentNullException("host");

            return MessageBuilder.New().
            Append("<stream:stream").
            AppendFormat(" to='{0}'", host).
            Append(" xmlns='jabber:client'").
            Append(" xmlns:stream='http://etherx.jabber.org/streams'").
            AppendFormatIf(version != null,
                            " version='{0}'", version).
            AppendFormatIf(language != null,
                            " xml:lang='{0}'", language).
            Append(">");
        }

        #region IConnectionPolicy Members

        /// <summary>
        /// 
        /// </summary>
        /// <param name="host"></param>
        /// <returns></returns>
        public String GetStreamStartHeader(String host)
        {
            return GetStreamStartHeader(host, null, null);
        }

        /// <summary>
        /// Gets a start stream request
        /// </summary>
        /// <returns></returns>
        public String GetStreamStartHeader(
            String host,
            Object version,
            String language
        )
        {
            return GetStreamStartHeaderCore(host, version, language);
        }

        #endregion
    }
}
